import express from 'express';

import ConstantValueController from '../controllers/constant-value';
import SysMenuController from '../controllers/sys-menu';
import HotelController from '../controllers/hotel';
import GenderController from '../controllers/gender';
import * as HotelValidate from '../validation/hotel';

import UserController from '../controllers/user';

import ContinentController from '../controllers/continent';
import CountryController from '../controllers/country';
import StateController from '../controllers/state';
// import ReportController from '../controllers/report';
import DashboardController from '../controllers/dashboard';
import AppParameterNameController from '../controllers/app-parameter-name';
import AppParameterValueController from '../controllers/app-parameter-value';
import RoomTypeController from '../controllers/room-type';
import RoomFloorController from '../controllers/room-floor';
import RoomFeatureController from '../controllers/room-feature';
import RoomController from '../controllers/room';
import DepositRuleController from '../controllers/deposit-rule';
import WeChatController from '../controllers/wechat';
import OpenUserController from '../controllers/open-user';
import RoomHistoryController from '../controllers/room-history';
import ReservationPrepayController from '../controllers/reservation-prepay';
import ReservationRefundController from '../controllers/reservation-refund';
import ReservationController from '../controllers/reservation';
import SmsLogController from '../controllers/sms-log';
import MiniTicketController from '../controllers/mini-ticket';

import Upload from './upload';

const router = express.Router();

router.get('/', (req, res) => {
  res.send('Welcome to NCloud');
});

router.get('/constant/values/key/:key/map/:map', ConstantValueController.findAll);

router.get('/genders', GenderController.findAll);
router.get('/genders/id/:id', GenderController.findOne);
router.post('/genders', GenderController.create);
router.put('/genders/id/:id', GenderController.update);
router.delete('/genders/id/:id', GenderController.destroy);

router.get('/sys-menus', SysMenuController.findAll);
router.get('/sys-menus/id/:id', SysMenuController.findOne);
router.post('/sys-menus', SysMenuController.create);
router.put('/sys-menus/id/:id', SysMenuController.update);
router.delete('/sys-menus/id/:id', SysMenuController.destroy);

router.get('/hotels', HotelController.findAll);
router.get('/hotels/id/:id', HotelController.findOne);
router.post('/hotels', HotelValidate.create, HotelController.create);
router.put('/hotels/id/:id', HotelValidate.update, HotelController.update);
router.delete('/hotels/id/:id', HotelController.destroy);

router.get('/continents', ContinentController.findAll);
router.get('/continents/id/:id', ContinentController.findOne);
router.post('/continents', ContinentController.create);
router.put('/continents/id/:id', ContinentController.update);
router.delete('/continents/id/:id', ContinentController.destroy);

router.get('/countries', CountryController.findAll);
router.get('/countries/id/:id', CountryController.findOne);
router.post('/countries', CountryController.create);
router.put('/countries/id/:id', CountryController.update);
router.delete('/countries/id/:id', CountryController.destroy);

router.get('/states', StateController.findAll);
router.get('/states/id/:id', StateController.findOne);
router.post('/states', StateController.create);
router.put('/states/id/:id', StateController.update);
router.delete('/states/id/:id', StateController.destroy);

router.get('/app-parameter-names', AppParameterNameController.findAll);
router.post('/app-parameter-names', AppParameterNameController.create);
router.put('/app-parameter-names/id/:id', AppParameterNameController.update);
router.get('/app-parameter-names/id/:id', AppParameterNameController.findOne);
router.post('/app-parameter-names/copy-to-hotels', AppParameterNameController.copyToHotels);

router.get('/app-parameter-values', AppParameterValueController.findAll);
router.put('/app-parameter-values/id/:id', AppParameterValueController.update);
router.get('/app-parameter-values/id/:id', AppParameterValueController.findOne);

router.post('/user/login', UserController.login);
router.post('/user/unlock', UserController.unlock);
router.post('/user/reset-password', UserController.resetPassword);

router.get('/user/loginOut', async (req, res, next) => {
  res.sendOk();
});

router.get('/user/info', UserController.getInfo);
router.get('/users', UserController.findAll);
router.get('/users/id/:id', UserController.findOne);
router.get('/users/login_name/:login_name', UserController.findUserByLoginName);
router.post('/users', UserController.create);
router.post('/users/hotel/:hotel_id', UserController.create);
router.post('/users/update-password', UserController.updatePassword);
router.get('/users/permissions/user/:user_id/hotel/:hotel_id', UserController.getUserHotelPermissions);
router.put('/users/id/:id', UserController.update);
// 授权主体
router.post('/users/grant/hotel', UserController.grantHotelToUser);
// 撤销授权主体
router.post('/users/revoke/hotel', UserController.revokeHotelToUser);
// 授权用户主体权限
router.post('/users/grant/permissions/user/:user_id/hotel/:hotel_id', UserController.grantHotelPermissionsToUser);
// 获取授权主体列表
router.get('/users/id/:id/grant/hotels', UserController.getGrantedHotels);
// 切换登录主体
router.post('/users/info/session-hotel/:hotel_id', UserController.updateLoginHotel);
router.delete('/users/id/:id', UserController.destroy);

// Dashboard
router.get('/dashboard/analysis/total', DashboardController.getAnalysisTotal);
router.get('/dashboard/admin/total', DashboardController.getAdminTotal);
router.get('/dashboard/admin/offline-hotels', DashboardController.getOfflineInterface);

// // 每周消费
// router.get('/dashboard/analysis/weekly-consumption', DashboardController.getMemberWeeklyConsumption);
// router.get('/dashboard/admin/weekly-consumption', DashboardController.getAdminMemberWeeklyConsumption);

// // 会员来源
// router.get('/dashboard/analysis/member-source', DashboardController.getMemberSource);
// router.get('/dashboard/admin/hotel-source', DashboardController.getHotelSource);

// 会员月度消费储值
router.get('/dashboard/analysis/monthly-payment', DashboardController.getMemberMonthlyPayments);

router.get('/room-types', RoomTypeController.findAll);
router.get('/room-types/id/:id', RoomTypeController.findOne);
router.post('/room-types', RoomTypeController.create);
router.post('/room-types/bulk', RoomTypeController.bulkCreate);
router.put('/room-types/id/:id', RoomTypeController.update);
router.delete('/room-types/id/:id', RoomTypeController.destroy);

router.get('/room-floors', RoomFloorController.findAll);
router.get('/room-floors/id/:id', RoomFloorController.findOne);
router.post('/room-floors', RoomFloorController.create);
router.post('/room-floors/bulk', RoomFloorController.bulkCreate);
router.put('/room-floors/id/:id', RoomFloorController.update);
router.delete('/room-floors/id/:id', RoomFloorController.destroy);

router.get('/room-features', RoomFeatureController.findAll);
router.get('/room-features/id/:id', RoomFeatureController.findOne);
router.post('/room-features', RoomFeatureController.create);
router.post('/room-features/bulk', RoomFeatureController.bulkCreate);
router.put('/room-features/id/:id', RoomFeatureController.update);
router.delete('/room-features/id/:id', RoomFeatureController.destroy);

router.get('/rooms', RoomController.findAll);
router.get('/rooms/id/:id', RoomController.findOne);
router.post('/rooms', RoomController.create);
router.post('/rooms/bulk', RoomController.bulkCreate);
router.put('/rooms/id/:id', RoomController.update);
router.delete('/rooms/id/:id', RoomController.destroy);

router.get('/deposit-rules', DepositRuleController.findAll);
router.get('/deposit-rules/id/:id', DepositRuleController.findOne);
router.post('/deposit-rules', DepositRuleController.create);
router.put('/deposit-rules/id/:id', DepositRuleController.update);
router.delete('/deposit-rules/id/:id', DepositRuleController.destroy);

router.get('/open-users', OpenUserController.findAll);
router.get('/open-users/id/:id', OpenUserController.findOne);
router.put('/open-users/id/:id', OpenUserController.update);
router.delete('/open-users/id/:id', OpenUserController.destroy);

router.get('/room-history', RoomHistoryController.findAll);
router.get('/room-history/id/:id', RoomHistoryController.findOne);
router.put('/room-history/id/:id', RoomHistoryController.update);

router.get('/reservation-prepay', ReservationPrepayController.findAll);
router.get('/reservation-prepay/id/:id', ReservationPrepayController.findOne);
router.put('/reservation-prepay/id/:id', ReservationPrepayController.update);

router.get('/wechat/jscode2session/:jsCode', WeChatController.jscode2session);
router.post('/wechat/wxpay-notify', WeChatController.wxpayNotify);
router.post('/wechat/wxpay-refund-notify', WeChatController.wxpayRefundNotify);
router.post('/wechat/reservation/assign-room', WeChatController.assignRoom);
router.get('/wechat/hotel-info', WeChatController.getHotelInfo);
router.get('/wechat/reservation/confirmation-number/:confirmNumber', WeChatController.getReservationByConfirmNumber);
router.get('/wechat/reservation-deposit/confirmation-number/:confirmNumber', WeChatController.getShareReservationDepositByConfirmNumber);
router.get('/wechat/room-availability', WeChatController.getRoomAvailability);
router.get('/wechat/billings/:openid', WeChatController.getBillByOpenID);
router.get('/wechat/room-history/:openid', WeChatController.getRoomHistoryByOpenID);
router.post('/wechat/mini-tickets', MiniTicketController.create);

router.get('/reservation/future-booking-summary', ReservationController.findAll);

router.post('/sms-logs/bulk/create', SmsLogController.bulkCreate);
router.get('/sms-logs', SmsLogController.findAll);
router.get('/sms-logs/sequence/:sequence', SmsLogController.findAllBySequence);

router.get('/mini-tickets', MiniTicketController.findAll);
router.get('/mini-tickets/id/:id', MiniTicketController.findOne);
router.put('/mini-tickets/resolve/id/:id', MiniTicketController.resolve);
router.post('/mini-tickets', MiniTicketController.create);
router.put('/mini-tickets/id/:id', MiniTicketController.update);
router.delete('/mini-tickets/id/:id', MiniTicketController.destroy);

router.post('/reservation-refund', ReservationRefundController.create);
router.get('/reservation-refund', ReservationRefundController.findAll);
router.get('/reservation-refund/summary', ReservationRefundController.getSummary);

router.use(Upload);
router.use('/wechat', Upload);

router.get('/code/:code', WeChatController.redirect);

// router.get('/mini/:code', )

export default router;
